module.exports = function($scope, $state, $modal,$stateParams, $resource,saveArticle,getArticle,findPidList){

    var id = $stateParams.id;
    console.log(id);
    $scope.obj = {
        'data' : ""
    };
    $scope.infoobj = {};
    if(id){
        getArticle.save({'id' : id},function(res){
            if(res.errcode === 0){
				console.log(res);                
                $scope.obj = res.data;
                $scope.infoobj = JSON.parse(res.data.data);
			}else{
				alert(res.errmsg);
			}
        })
    }
    
	$scope.save = function(){
        $scope.obj.data = JSON.stringify($scope.infoobj);
        
		saveArticle.save(($scope.obj), function(res){
            console.log($scope.obj);
			if(res.errcode === 0){
                consol.log($scope.obj);
                console.log('添加成功');
				console.log(res);
			}else{
				alert(res.errmsg);
			}
		});
	};

    // 上级分类列表
	$scope.pidlist = function(){
        findPidList.save({},function(res){
            if(res.errcode === 0){
                console.log(res);
                $scope.pid_list = res.data;
            } else {
                alert(res.errmsg);
            }
        })
	}
	$scope.pidlist();


	//取消
	$scope.cancel = function () {
		$scope.what = 'list';
		$scope.status.rolelist = true;
	};

    $scope.image = function(){
		var para = $state.get('app.imageupload');

        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  
            console.log(result);  
            $scope.imagearr = JSON.stringify(result);
            // form.result['templete_lock_data_json'] = JSON.stringify(result.lock);
            // form.result['templete_check_data_json'] = result.unlock;

        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
	};

    $scope.viewimage = function(){
		var para = $state.get('app.imageupload');

        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  
            console.log(result);  
            $scope.infoobj.viewimage = result;
            // $scope.imagearr = JSON.stringify(result);
            // form.result['templete_lock_data_json'] = JSON.stringify(result.lock);
            // form.result['templete_check_data_json'] = result.unlock;

        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
	};

    $scope.meiimage = function(){
		var para = $state.get('app.imageupload');

        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  
            console.log(result); 
            $scope.infoobj.meiimage = result;
             
            // $scope.imagearr = JSON.stringify(result);
            // form.result['templete_lock_data_json'] = JSON.stringify(result.lock);
            // form.result['templete_check_data_json'] = result.unlock;

        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
	};
     $scope.aerialimage = function(){
		var para = $state.get('app.imageupload');

        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  
            console.log(result);  
            $scope.infoobj.aerialimage = result;
            
            // $scope.imagearr = JSON.stringify(result);
            // form.result['templete_lock_data_json'] = JSON.stringify(result.lock);
            // form.result['templete_check_data_json'] = result.unlock;

        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
	};


	

 };






